package com.kaifamiao.demo.d0811;

import java.util.Scanner;

public class Bank {

    private MyList accounts;

    private Scanner in = new Scanner(System.in);

    public Bank(){
        accounts = new MyList();
    }

    public void start(){
        System.out.println("欢迎光临 开发喵网上银行 v1.1");

        while (true){
            menu();
        }
    }

    private void menu(){
        System.out.println("请根据提示，输入数字选择相应的功能");
        System.out.println("1. 开户");
        System.out.println("2. 查询所有账户信息(管理员)");
        System.out.println("0. 退出");
        System.out.println("请选择：");
        int type = in.nextInt();
        switch (type){
            case 1:
                create();
                break;
            case 2:
                findAll();
                break;
            case 0:
                exit();
                break;
            default:
                System.err.println("输入错误，请重新选择。");
        }
    }

    private void create(){
        System.out.println("开户中，请输入开户人姓名：");
        String name = in.next();
        System.out.println("请设置账户密码：");
        String password = in.next();

        long cardId = System.currentTimeMillis();

        Account account = new Account(cardId, password, 0.0, name);

        // 把用户信息存起来
        accounts.add(account);
        System.out.println("开户成功，卡号是：" + cardId);
    }

    private void findAll(){
        System.out.println("共有 " + accounts.size() + " 个账户，分别是：");
        System.out.println(accounts.toString());
    }

    private void exit(){
        System.out.println("感谢使用，欢迎下次光临。");
        System.exit(0);
    }
}
